package org.shop.controller.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.shop.entity.security.MyUserDetail;
import org.shop.service.GoodsAppraisesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class WebGoodsAppraisesController {
	
	private static Logger logger = LogManager.getLogger(WebGoodsAppraisesController.class);
	
	@Autowired
    private GoodsAppraisesService goodsAppraisesService;
	
	/**
	 * 商家获取评论
	 * @param req
	 * @return
	 */
	@RequestMapping("web/getGoodsAppraisesInfo")
	@ResponseBody
	public Map<String,Object> getGoodsAppraisesInfo(HttpServletRequest req){
		Map<String,Object> map = new HashMap<String,Object>();
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	 	String currentPage = req.getParameter("offset");
        String pageSize = req.getParameter("limit");
        String startTime = req.getParameter("startTime");
        String selectName = req.getParameter("selectName");
        String endTime = req.getParameter("endTime") == null ? "" : req.getParameter("endTime")+"23:59:59";
        try {
        	Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("startPage", Integer.parseInt(currentPage));
            paramMap.put("pageSize", Integer.parseInt(pageSize));
            paramMap.put("startTime", startTime);
            paramMap.put("endTime", endTime);
            paramMap.put("merchantId", ud.getMerchantId());
            paramMap.put("selectName", selectName);
            map = goodsAppraisesService.getGoodsAppraisesInfo(paramMap);
        }catch(Exception e) {
        	e.printStackTrace();
        	logger.error(e.getMessage());
        }
        return map;
	}
	
	
}
